from rest_framework import serializers
from orders.models import OrderInfo, OrderGoods


class SKUSimpleSerializer(serializers.Serializer):
    name = serializers.CharField()
    default_image = serializers.ImageField()


class OrderGoodsSerializer(serializers.Serializer):
    count = serializers.IntegerField()
    price = serializers.DecimalField(max_digits=10, decimal_places=2) ## 必须指定这两个参数
    sku = SKUSimpleSerializer(read_only=True)


class OrderSerializer(serializers.ModelSerializer):
    skus = OrderGoodsSerializer(many=True, read_only=True)

    class Meta:
        model = OrderInfo
        fields = '__all__'
